package com.samphanie.auiu.biz_detail.biz.notice

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.samphanie.auiu.biz_detail.R
import com.samphanie.auiu.biz_detail.databinding.ActivityNoticeListBinding
import com.samphanie.auiu.common.ui.component.BaseAppBVMActivity
import com.samphanie.auiu.common.ui.view.EmptyView
import com.samphanie.auiu.pub_mod.model.CourseNotice
import com.samphanie.auiu.ui.item.AuiuAdapter

@Route(path = "/notice/list")
class NoticeListActivity : BaseAppBVMActivity<ActivityNoticeListBinding, NoticeListViewModel>() {

    private lateinit var adapter: AuiuAdapter
    private lateinit var courseNotice: CourseNotice
    private var emptyView: EmptyView? = null

    override fun createViewModel(): NoticeListViewModel {
        return NoticeListViewModel()
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_notice_list
    }

    override fun initialize(savedInstanceState: Bundle?) {

        binding.actionBack.setOnClickListener {
            backPress(null)
        }

        initUI()

        viewModel.queryCourseNotice().observe(this) {
            if (it != null) {
                bindData(it)
            }
        }
    }

    private fun bindData(data: CourseNotice) {
        courseNotice = data
        data.list?.map {
            adapter.addItemAt(0, NoticeItem(it), true)
        }
    }

    private fun initUI() {
        // 初始化Recycleview
        val llm = LinearLayoutManager(this)
        adapter = AuiuAdapter(this)
        binding.noticeList.layoutManager = llm
        binding.noticeList.adapter = adapter
    }

}